package com.lx.video.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lx.bilibili.entity.Video;
import com.lx.bilibili.entity.VideoEx;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface VideoExMapper extends BaseMapper<Video> {

    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id and a.state = 1 \n" +
            "	AND ( b.NAME LIKE CONCAT('%', #{searchText} ,'%') OR a.vname LIKE CONCAT('%', #{searchText} ,'%') );")

    List<VideoEx> searchByText(String searchText);

    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id  and a.state = 1 \n" +
            "	order by a.id limit #{page}, #{count};")

    List<VideoEx> recVideo(int page, int count);

    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id  and a.state = 1  " +
            "and ( b.NAME LIKE CONCAT('%', #{searchText} ,'%') OR a.vname LIKE CONCAT('%', #{searchText} ,'%'))\n" +
            "order by a.vcount DESC;")

    List<VideoEx> mostPlay(String searchText);


    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id  and a.state = 1  " +
            "and ( b.NAME LIKE CONCAT('%', #{searchText} ,'%') OR a.vname LIKE CONCAT('%', #{searchText} ,'%'))\n" +
            "	order by a.time DESC;")

    List<VideoEx> newPublish(String searchText);

    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id  and a.state = 1  " +
            "and ( b.NAME LIKE CONCAT('%', #{searchText} ,'%') OR a.vname LIKE CONCAT('%', #{searchText} ,'%'))\n" +
            "	order by a.danmucount DESC;")

    List<VideoEx> mostDanmu(String searchText);

    @Select("SELECT\n" +
            "	a.*, b.name \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id  and a.state = 1  ")
    List<VideoEx> getHotVideo();


    @Select("SELECT\n" +
            "	* \n" +
            "FROM\n" +
            "	video a,\n" +
            "	`user` b \n" +
            "WHERE\n" +
            "	a.uid = b.id \n" +
            "	AND (\n" +
            "	a.vname LIKE #{searchText} \n" +
            "	OR a.tag LIKE #{searchText})")
    List<VideoEx> searchByTextAndType(String searchText);

}
